package io.renren.modules.jsf.service.impl;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.jsf.dao.QianDaoDao;
import io.renren.modules.jsf.entity.QianDaoEntity;
import io.renren.modules.jsf.service.QianDaoService;


@Service("qianDaoService")
public class QianDaoServiceImpl extends ServiceImpl<QianDaoDao, QianDaoEntity> implements QianDaoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<QianDaoEntity> page = this.page(
                new Query<QianDaoEntity>().getPage(params),
                new QueryWrapper<QianDaoEntity>().orderByDesc("create_time")
        );

        return new PageUtils(page);
    }

    @Override
    public QianDaoEntity selectByName(String userName) {

        return baseMapper.selectOne(new QueryWrapper<QianDaoEntity>().eq("user_name", userName));
    }

    @Override
    public QianDaoEntity selectByTime(String date) {
        return baseMapper.selectOne(new QueryWrapper<QianDaoEntity>().like("create_time", date));
    }

    @Override
    public QianDaoEntity selectByTimeAndName(String date, String username) {
        return baseMapper.selectOne(new QueryWrapper<QianDaoEntity>().eq("user_name", username).like("create_time", date));
    }

}
